#include "Victory.h"
#include "Global.h"

Victory::Victory(void)
{
	m_font = new CGEFont("lazy.ttf", 25 ); 
	m_ShowTime = 0;
}

Victory::~Victory(void)
{
}
#include <iostream>
void Victory::ShowWinner(GameResult winnerIndex,bool singlePlayer)
{
	std::cout << "show time:"<< m_ShowTime <<std::endl;
	m_ShowTime = SDL_GetTicks();
	if(singlePlayer)
	{
		if(winnerIndex == WHITE_WIN)
		{
			m_font->AddText("You Win!","YouWin",0,SCREEN_HEIGHT/2-20,255,0,0);
			std::cout << "You Win"<<std::endl;
		}
		else if(winnerIndex == BLACK_WIN)
		{
			m_font->AddText("AI Win!","AIWin",0 ,SCREEN_HEIGHT / 2 - 20,255,0,0);
			std::cout <<"AI win"<<std::endl;
		}
		else if(winnerIndex == DRAW_GAME)
		{
			m_font->AddText("Draw!","DrawOne",0 ,SCREEN_HEIGHT / 2 - 20,255,0,0);
			std::cout << "Draw"<< std::endl;
		}
	}
	else
	{
		if(winnerIndex == WHITE_WIN)
		{
			m_font->AddText("White Win!","WhiteWin",0 ,SCREEN_HEIGHT / 2 - 20,255,0,0);
			std::cout << "White Win"<<std::endl;
		}
		else if(winnerIndex == BLACK_WIN)
		{
			m_font->AddText("Black win!","BlackWin", 0 ,SCREEN_HEIGHT / 2 - 20,255,0,0);
			std::cout <<"Black win"<<std::endl;
		}
		else if(winnerIndex == DRAW_GAME)
		{
			m_font->AddText("Draw!","DrawTwo",0 ,SCREEN_HEIGHT / 2 - 20,255,0,0);
			std::cout << "Draw"<< std::endl;
		}
	}
}

void Victory::Render()
{
	if(m_ShowTime != 0)
	{
		m_font->Render();
	}
}
bool Victory::Update()
{
	//std::cout << SDL_GetTicks() << " time "<< m_ShowTime <<std::endl;
	if(SDL_GetTicks() - m_ShowTime > 5000 && m_ShowTime != 0)
	{
		std::cout << "wait end"<< std::endl;
		m_ShowTime = 0;
		return false;
	}
	return true;
}